<?php

namespace App\Console\Commands;

use App\Http\Controllers\Admin\Business\Repository\Combo;
use App\Http\Controllers\Admin\Business\Repository\ComboOrder;
use App\Http\Controllers\Admin\Finance\Repository\Withdraw;
use App\Member;
use App\PayOrder;
use App\Repositories\DistributeRepository;
use Illuminate\Console\Command;

class MemberLogHanle extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'member:log';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '统计订单数提成';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {  //修改退款逻辑
       /* $withdraw= Withdraw::all();
        foreach ($withdraw as $v){
            if($v['status']==2){
                Member::where('id',$v->member_id)->decrement('wallet_push_money',$v->price);
                Member::where('id',$v->member_id)->increment('wallet_used_push_money',$v->price);
            }
        }*/
       $combo=Combo::pluck('rate','id')->toArray();
       //修改每个订单的rate
        ComboOrder::chunk(100,function($comboOrder)use($combo){

            foreach ($comboOrder as $v){
                if($v->combo_id==2&&strtotime($v->created_at)<1534953600){
                    $v->rate=66.8896;
                }else{
                    $v->rate=$combo[$v->combo_id];
                }
                $v->save();
                $this->info($v->id);
            }
        });
    }
}
